import axios from 'axios'

const instance = axios.create({
  baseURL: "http://192.168.113.249:8081/cms",

})

//添加请求拦截器
instance.interceptors.request.use((config) => {
  console.log("求拦截器...携带token");
 //有token则携带token
 let token = localStorage.getItem('x-auth-token');
 if (token) {
     config.headers['x-auth-token'] = token;
 }
  return config;
}, (error) => {
  return Promise.reject(error)
})
//响应拦截器
instance.interceptors.response.use(function (response) {
  if (response.data.code != 0 && response.data.code != 400 && response.data.code != 407) {
    alert(response.data.message || response.data.msg);
    return;
}
  return response.data
}, function (error) {
  return Promise.reject(error)
})

export default instance